/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import drawing from "@ohos.graphics.drawing";
import common2D from '@ohos.graphics.common2D';
import {TestBase, TestFunctionStyleType} from '../../pages/testbase';
import { OHRandom } from '../../utils/OHRandom';

const TAG = '[BezierBench]';

export class PenGetFillPath extends TestBase {
  public constructor() {
    super();

  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let rand: OHRandom = new OHRandom();
    let pen = new drawing.Pen();
    this.ApplyPenStyle(pen, TestFunctionStyleType.DRAW_STYLE_TYPE_2);
    canvas.attachPen(pen);
    let pathDst: drawing.Path = new drawing.Path();

    for (let i = 0; i < this.testCount_; i++) {
      let pathSrc: drawing.Path = new drawing.Path();
      let xMove: number = rand.nextULessThan(this.width_);
      let yMove: number = rand.nextULessThan(this.height_);
      let xLineTo: number = rand.nextULessThan(this.width_);
      let yLineTo: number = rand.nextULessThan(this.height_);
      pathSrc.moveTo(xMove, yMove);
      pathSrc.lineTo(xLineTo, yLineTo);

      pen.getFillPath(pathSrc, pathDst);
    }
    canvas.drawPath(pathDst);
    canvas.detachPen();
  }

  public OnTestFunction(canvas: drawing.Canvas) {
    {
      let pen = new drawing.Pen();
      this.ApplyPenStyle(pen, TestFunctionStyleType.DRAW_STYLE_TYPE_2);
      canvas.attachPen(pen);

      let pathSrc: drawing.Path = new drawing.Path();
      let pathDst: drawing.Path = new drawing.Path();
      pathSrc.moveTo(0, 0);
      pathSrc.lineTo(this.width_, this.height_);

      pen.getFillPath(pathSrc, pathDst);

      canvas.drawPath(pathDst);
      canvas.drawPath(pathSrc);

      canvas.detachPen();
    }
  }
}
